/**
 * 作者: wgx
 * 日期: 2024-12-03 16:14:36
 * 备注: 用户物资争夺模块数据
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserSnatchInfo;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserSnatchInfoModel extends BaseModel implements Model {
    public static final String LISTKEY = "";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // 用户ID
    protected int money; // 贸易币数量
    protected long resetTimeWeek; // 每周的重置时间
    protected String partnerIds = ""; // 匹配战上阵的干员列表
    protected int inspireNum; // 鼓舞次数
    protected long enemyId; // 敌人的userid
    protected String partnerIdsChallege = ""; // 挑战时上阵的干员列表
    protected int transferLevel; // 中转站等级
    protected long transferTime; // 中转站奖励的领取时间
    protected String honerReward = ""; // 荣誉奖励的领取记录
    protected int isRankReward; // 是否已领取榜单奖励
    protected long dateKey; // 哪周的榜单,周一0点的时间戳 (领完奖励更新)
    protected int maxKonum; // 单场最多击败几人
    protected int isProtect; // 是否被保护 (1-被保护,不能再被匹配到)
    protected long protectTime; // 保护的起始时间
    protected long defendTime; // 被打的起始时间
    protected int defendNum; // 被打次数
    protected long lastEnemyId; // 上一次打的玩家
    protected long resetTimeDay; // 每日的重置时间
    protected int offerFightNum; // 悬赏追击次数 (每日重置)
    protected long lastEnemyid; // 今日最后一次挑战名人广播的dbid (每日重置)

    public void reset() {
    }

    protected String getKey() {
        return "UserSnatchInfo." + id;
    }

    protected String getListKey() {
        return null;
    }

    protected String getListItemKey() {
        return null;
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_snatch_info"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, id, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, id, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // 用户ID
        obj.put("money", money); // 贸易币数量
        obj.put("resetTimeWeek", resetTimeWeek); // 每周的重置时间
        obj.put("partnerIds", partnerIds); // 匹配战上阵的干员列表
        obj.put("inspireNum", inspireNum); // 鼓舞次数
        obj.put("enemyId", enemyId); // 敌人的userid
        obj.put("partnerIdsChallege", partnerIdsChallege); // 挑战时上阵的干员列表
        obj.put("transferLevel", transferLevel); // 中转站等级
        obj.put("transferTime", transferTime); // 中转站奖励的领取时间
        obj.put("honerReward", honerReward); // 荣誉奖励的领取记录
        obj.put("isRankReward", isRankReward); // 是否已领取榜单奖励
        obj.put("dateKey", dateKey); // 哪周的榜单,周一0点的时间戳 (领完奖励更新)
        obj.put("maxKonum", maxKonum); // 单场最多击败几人
        obj.put("isProtect", isProtect); // 是否被保护 (1-被保护,不能再被匹配到)
        obj.put("protectTime", protectTime); // 保护的起始时间
        obj.put("defendTime", defendTime); // 被打的起始时间
        obj.put("defendNum", defendNum); // 被打次数
        obj.put("lastEnemyId", lastEnemyId); // 上一次打的玩家
        obj.put("resetTimeDay", resetTimeDay); // 每日的重置时间
        obj.put("offerFightNum", offerFightNum); // 悬赏追击次数 (每日重置)
        obj.put("lastEnemyid", lastEnemyid); // 今日最后一次挑战名人广播的dbid (每日重置)
        return obj;
    }

    public PBUserSnatchInfo.Builder takeInitBuilder() {
        PBUserSnatchInfo.Builder sb = PBUserSnatchInfo.newBuilder();
        if (money != 0) {
            sb.setMoney(money);
        }
        if (!partnerIds.isEmpty()) {
            sb.setPartnerIds(partnerIds);
        }
        if (inspireNum != 0) {
            sb.setInspireNum(inspireNum);
        }
        if (enemyId != 0) {
            sb.setEnemyId(enemyId);
        }
        if (!partnerIdsChallege.isEmpty()) {
            sb.setPartnerIdsChallege(partnerIdsChallege);
        }
        if (transferLevel != 0) {
            sb.setTransferLevel(transferLevel);
        }
        if (transferTime != 0) {
            sb.setTransferTime(transferTime);
        }
        if (!honerReward.isEmpty()) {
            sb.setHonerReward(honerReward);
        }
        if (isRankReward != 0) {
            sb.setIsRankReward(isRankReward);
        }
        if (offerFightNum != 0) {
            sb.setOfferFightNum(offerFightNum);
        }
        if (lastEnemyid != 0) {
            sb.setLastEnemyid(lastEnemyid);
        }
        return sb;
    }

    public PBUserSnatchInfo.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUserSnatchInfo.Builder sb = PBUserSnatchInfo.newBuilder();
        if (isFieldUpdate("money")) {
            sb.setMoney(money);
        }
        if (isFieldUpdate("partnerIds")) {
            sb.setPartnerIds(partnerIds);
        }
        if (isFieldUpdate("inspireNum")) {
            sb.setInspireNum(inspireNum);
        }
        if (isFieldUpdate("enemyId")) {
            sb.setEnemyId(enemyId);
        }
        if (isFieldUpdate("partnerIdsChallege")) {
            sb.setPartnerIdsChallege(partnerIdsChallege);
        }
        if (isFieldUpdate("transferLevel")) {
            sb.setTransferLevel(transferLevel);
        }
        if (isFieldUpdate("transferTime")) {
            sb.setTransferTime(transferTime);
        }
        if (isFieldUpdate("honerReward")) {
            sb.setHonerReward(honerReward);
        }
        if (isFieldUpdate("isRankReward")) {
            sb.setIsRankReward(isRankReward);
        }
        if (isFieldUpdate("offerFightNum")) {
            sb.setOfferFightNum(offerFightNum);
        }
        if (isFieldUpdate("lastEnemyid")) {
            sb.setLastEnemyid(lastEnemyid);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public int getMoney() {
        return money;
    }

    public void putMoney(int money) {
        if (this.money != money) {
            this.money = money;
            updateRedisHashField(getKey(), "money", this.money);
        }
    }

    public void addMoney(int value) {
        this.money += value;
        updateRedisHashField(getKey(), "money", this.money);
    }

    public long getResetTimeWeek() {
        return resetTimeWeek;
    }

    public void putResetTimeWeek(long resetTimeWeek) {
        if (this.resetTimeWeek != resetTimeWeek) {
            this.resetTimeWeek = resetTimeWeek;
            updateRedisHashField(getKey(), "resetTimeWeek", this.resetTimeWeek);
        }
    }

    public void addResetTimeWeek(long value) {
        this.resetTimeWeek += value;
        updateRedisHashField(getKey(), "resetTimeWeek", this.resetTimeWeek);
    }

    public String getPartnerIds() {
        return partnerIds;
    }

    public void putPartnerIds(String partnerIds) {
        if (!this.partnerIds.equals(partnerIds)) {
            this.partnerIds = partnerIds;
            updateRedisHashField(getKey(), "partnerIds", this.partnerIds);
        }
    }

    public int getInspireNum() {
        return inspireNum;
    }

    public void putInspireNum(int inspireNum) {
        if (this.inspireNum != inspireNum) {
            this.inspireNum = inspireNum;
            updateRedisHashField(getKey(), "inspireNum", this.inspireNum);
        }
    }

    public void addInspireNum(int value) {
        this.inspireNum += value;
        updateRedisHashField(getKey(), "inspireNum", this.inspireNum);
    }

    public long getEnemyId() {
        return enemyId;
    }

    public void putEnemyId(long enemyId) {
        if (this.enemyId != enemyId) {
            this.enemyId = enemyId;
            updateRedisHashField(getKey(), "enemyId", this.enemyId);
        }
    }

    public void addEnemyId(long value) {
        this.enemyId += value;
        updateRedisHashField(getKey(), "enemyId", this.enemyId);
    }

    public String getPartnerIdsChallege() {
        return partnerIdsChallege;
    }

    public void putPartnerIdsChallege(String partnerIdsChallege) {
        if (!this.partnerIdsChallege.equals(partnerIdsChallege)) {
            this.partnerIdsChallege = partnerIdsChallege;
            updateRedisHashField(getKey(), "partnerIdsChallege", this.partnerIdsChallege);
        }
    }

    public int getTransferLevel() {
        return transferLevel;
    }

    public void putTransferLevel(int transferLevel) {
        if (this.transferLevel != transferLevel) {
            this.transferLevel = transferLevel;
            updateRedisHashField(getKey(), "transferLevel", this.transferLevel);
        }
    }

    public void addTransferLevel(int value) {
        this.transferLevel += value;
        updateRedisHashField(getKey(), "transferLevel", this.transferLevel);
    }

    public long getTransferTime() {
        return transferTime;
    }

    public void putTransferTime(long transferTime) {
        if (this.transferTime != transferTime) {
            this.transferTime = transferTime;
            updateRedisHashField(getKey(), "transferTime", this.transferTime);
        }
    }

    public void addTransferTime(long value) {
        this.transferTime += value;
        updateRedisHashField(getKey(), "transferTime", this.transferTime);
    }

    public String getHonerReward() {
        return honerReward;
    }

    public void putHonerReward(String honerReward) {
        if (!this.honerReward.equals(honerReward)) {
            this.honerReward = honerReward;
            updateRedisHashField(getKey(), "honerReward", this.honerReward);
        }
    }

    public int getIsRankReward() {
        return isRankReward;
    }

    public void putIsRankReward(int isRankReward) {
        if (this.isRankReward != isRankReward) {
            this.isRankReward = isRankReward;
            updateRedisHashField(getKey(), "isRankReward", this.isRankReward);
        }
    }

    public void addIsRankReward(int value) {
        this.isRankReward += value;
        updateRedisHashField(getKey(), "isRankReward", this.isRankReward);
    }

    public long getDateKey() {
        return dateKey;
    }

    public void putDateKey(long dateKey) {
        if (this.dateKey != dateKey) {
            this.dateKey = dateKey;
            updateRedisHashField(getKey(), "dateKey", this.dateKey);
        }
    }

    public void addDateKey(long value) {
        this.dateKey += value;
        updateRedisHashField(getKey(), "dateKey", this.dateKey);
    }

    public int getMaxKonum() {
        return maxKonum;
    }

    public void putMaxKonum(int maxKonum) {
        if (this.maxKonum != maxKonum) {
            this.maxKonum = maxKonum;
            updateRedisHashField(getKey(), "maxKonum", this.maxKonum);
        }
    }

    public void addMaxKonum(int value) {
        this.maxKonum += value;
        updateRedisHashField(getKey(), "maxKonum", this.maxKonum);
    }

    public int getIsProtect() {
        return isProtect;
    }

    public void putIsProtect(int isProtect) {
        if (this.isProtect != isProtect) {
            this.isProtect = isProtect;
            updateRedisHashField(getKey(), "isProtect", this.isProtect);
        }
    }

    public void addIsProtect(int value) {
        this.isProtect += value;
        updateRedisHashField(getKey(), "isProtect", this.isProtect);
    }

    public long getProtectTime() {
        return protectTime;
    }

    public void putProtectTime(long protectTime) {
        if (this.protectTime != protectTime) {
            this.protectTime = protectTime;
            updateRedisHashField(getKey(), "protectTime", this.protectTime);
        }
    }

    public void addProtectTime(long value) {
        this.protectTime += value;
        updateRedisHashField(getKey(), "protectTime", this.protectTime);
    }

    public long getDefendTime() {
        return defendTime;
    }

    public void putDefendTime(long defendTime) {
        if (this.defendTime != defendTime) {
            this.defendTime = defendTime;
            updateRedisHashField(getKey(), "defendTime", this.defendTime);
        }
    }

    public void addDefendTime(long value) {
        this.defendTime += value;
        updateRedisHashField(getKey(), "defendTime", this.defendTime);
    }

    public int getDefendNum() {
        return defendNum;
    }

    public void putDefendNum(int defendNum) {
        if (this.defendNum != defendNum) {
            this.defendNum = defendNum;
            updateRedisHashField(getKey(), "defendNum", this.defendNum);
        }
    }

    public void addDefendNum(int value) {
        this.defendNum += value;
        updateRedisHashField(getKey(), "defendNum", this.defendNum);
    }

    public long getLastEnemyId() {
        return lastEnemyId;
    }

    public void putLastEnemyId(long lastEnemyId) {
        if (this.lastEnemyId != lastEnemyId) {
            this.lastEnemyId = lastEnemyId;
            updateRedisHashField(getKey(), "lastEnemyId", this.lastEnemyId);
        }
    }

    public void addLastEnemyId(long value) {
        this.lastEnemyId += value;
        updateRedisHashField(getKey(), "lastEnemyId", this.lastEnemyId);
    }

    public long getResetTimeDay() {
        return resetTimeDay;
    }

    public void putResetTimeDay(long resetTimeDay) {
        if (this.resetTimeDay != resetTimeDay) {
            this.resetTimeDay = resetTimeDay;
            updateRedisHashField(getKey(), "resetTimeDay", this.resetTimeDay);
        }
    }

    public void addResetTimeDay(long value) {
        this.resetTimeDay += value;
        updateRedisHashField(getKey(), "resetTimeDay", this.resetTimeDay);
    }

    public int getOfferFightNum() {
        return offerFightNum;
    }

    public void putOfferFightNum(int offerFightNum) {
        if (this.offerFightNum != offerFightNum) {
            this.offerFightNum = offerFightNum;
            updateRedisHashField(getKey(), "offerFightNum", this.offerFightNum);
        }
    }

    public void addOfferFightNum(int value) {
        this.offerFightNum += value;
        updateRedisHashField(getKey(), "offerFightNum", this.offerFightNum);
    }

    public long getLastEnemyid() {
        return lastEnemyid;
    }

    public void putLastEnemyid(long lastEnemyid) {
        if (this.lastEnemyid != lastEnemyid) {
            this.lastEnemyid = lastEnemyid;
            updateRedisHashField(getKey(), "lastEnemyid", this.lastEnemyid);
        }
    }

    public void addLastEnemyid(long value) {
        this.lastEnemyid += value;
        updateRedisHashField(getKey(), "lastEnemyid", this.lastEnemyid);
    }

}